package orz.itrip.biz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import orz.itrip.DtoUtils;
import orz.itrip.biz.service.CommentService;
import orz.itrip.biz.vo.GetCommentVo;
import orz.itrip.dto.Dto;
import orz.itrip.pojo.Comment;
import orz.itrip.vo.CommentImgVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/api/comment/")
@Api(tags = "评论",description = "文档说明",hidden = true)
public class CommentController {

    @Resource
    private CommentService commentService;

    @RequestMapping(value = "upload",headers = "token",method = RequestMethod.POST)
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto upload(@RequestParam(value = "file",required = false)MultipartFile file, HttpServletRequest request) throws IOException {
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.upload(file);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @PostMapping(value = "add",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto add(@RequestBody CommentImgVo commentImgVo, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.add(commentImgVo,request.getHeader("token"));
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @GetMapping(value = "gettraveltype",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto gettraveltype(HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.gettraveltype();
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @GetMapping(value = "gethoteldesc/{hotelId}",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto gethoteldesc(@PathVariable Long hotelId, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.gethoteldesc(hotelId);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @GetMapping(value = "getimg/{hotelId}",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto getimg(@PathVariable Long hotelId, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.getimg(hotelId);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @PostMapping(value = "getcommentlist",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto getcommentlist(@RequestBody GetCommentVo getCommentVo, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.getcommentlist(getCommentVo);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @GetMapping(value = "gethotelscore/{hotelId}",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto gethotelscore(@PathVariable(value = "hotelId") Long hotelId, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.gethotelscore(hotelId);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @GetMapping(value = "getcount/{hotelId}",headers = "token")
    @ApiOperation( value = "查询酒店视频详情",notes = "查询酒店视频详情")
    public Dto getcount(@PathVariable(value = "hotelId") Long hotelId, HttpServletRequest request){
        if (!StringUtils.isEmpty(request.getHeader("token"))){
            return commentService.getcount(hotelId);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
}
